package com.centit.airplanebaseinfo.controller;

import com.centit.airplanebaseinfo.po.AirplaneBaseinfo;

import com.centit.airplaneinfo_db.po.DbRecord;
import com.centit.importData.po.ExportExcelUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.*;
import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.centit.airplanebaseinfo.service.AirplaneBaseinfoManager;
import com.centit.dtjktxlog.service.JddtDtjktxlogManager;
import com.centit.flowNode.po.FlowNode;
import com.centit.flowNode.service.FlowNodeManager;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.centit.framework.common.JsonResultUtils;
import com.centit.framework.common.ResponseMapData;
import com.centit.framework.components.CodeRepositoryUtil;
import com.centit.framework.core.controller.BaseController;
import com.centit.framework.core.dao.CodeBook;
import com.centit.framework.jdbc.dao.DatabaseOptUtils;
import com.centit.framework.model.basedata.IRoleInfo;
import com.centit.framework.model.basedata.IUnitInfo;
import com.centit.framework.model.basedata.IUserInfo;
import com.centit.framework.security.model.CentitUserDetails;
import com.centit.framework.system.po.UnitInfo;
import com.centit.ideaInfo.po.IdeaInfo;
import com.centit.ideaInfo.service.IdeaInfoManager;
import com.centit.jdghgl.po.Jdghgl;
import com.centit.jdghgl.service.JdghglManager;
import com.centit.support.algorithm.UuidOpt;
import com.centit.support.database.utils.PageDesc;
import com.centit.util.LayuiResultUtil;
import com.centit.util.ZipUtil;
import com.google.common.io.CharStreams;

/**
 * AirplaneBaseinfo  Controller.
 * create by scaffold 2020-03-13 
 * @author 脚手架，改成开发者的名字
 * 飞机基础信息飞机基础信息   
*/


@Controller
@RequestMapping("/airplanebaseinfo/airplanebaseinfo")
public class AirplaneBaseinfoController  extends BaseController {
	private static final Log log = LogFactory.getLog(AirplaneBaseinfoController.class);
	
	@Resource
	private AirplaneBaseinfoManager airplaneBaseinfoMag;
	@Resource
	private JdghglManager jdghglMag;
	@Resource
	private JddtDtjktxlogManager jddtDtjktxlogManager;
	@Resource
	private IdeaInfoManager ideaInfoMag;
	@Resource
	private FlowNodeManager flowNodeMag;
    /**
     * 查询所有   飞机基础信息  列表
     *
     * @param field    json中只保存需要的属性名
     * @param request  {@link HttpServletRequest}
     * @param response {@link HttpServletResponse}
     * @return {data:[]}
     */
    @RequestMapping(method = RequestMethod.GET)
    public void list(String[] field, PageDesc pageDesc, HttpServletRequest request, HttpServletResponse response) {
    	String limit = request.getParameter("limit");
        if (StringUtils.isBlank(limit)) {
            limit = "10";
        }
        pageDesc.setPageSize(Integer.parseInt(limit));
    	Map<String, Object> searchColumn = convertSearchColumn(request);
    	//searchColumn.put("orderby", " TO_NUMBER(a.CCXLH) ");
    	searchColumn.put("orderby", " a.INS_TIME DESC ");
    	if(searchColumn.get("field")!=null&&StringUtils.isNotBlank(searchColumn.get("field").toString())){
    		String orderby=searchColumn.get("field").toString();
    		if("endTime".equals(orderby)){
    			orderby=" a.END_TIME ";
    		}else if("airModel".equals(orderby)){
    			orderby=" a.AIR_MODEL ";
    		} else if("haveName".equals(orderby)){
    			orderby=" a.HAVE_NAME ";
    		} else if("ccxlh".equals(orderby)){
    			orderby=" TO_NUMBER(a.CCXLH) ";
    		}else if("maxZl".equals(orderby)){
    			orderby=" a.max_zl ";
    		}
    		String order=" asc ";
    		if(searchColumn.get("order")!=null&&StringUtils.isNotBlank(searchColumn.get("order").toString())){
    			order="  "+searchColumn.get("order").toString();
    		}
    		orderby+=order;
    		searchColumn.put("orderby", orderby);
    	}
    	searchColumn.put("dataValid", "T");
    	JSONArray jsonArrayObjects = new JSONArray();
    	CentitUserDetails cud = getLoginUser(request);
		List<? extends IRoleInfo> IRoleInfos = cud.getUserRoles();
		jsonArrayObjects = airplaneBaseinfoMag.getAirplaneBaseinfoList( searchColumn, pageDesc);
        for (int i = 0; i < jsonArrayObjects.size(); i++) {
            JSONObject jsonObject = jsonArrayObjects.getJSONObject(i);
            if (StringUtils.isNotEmpty(jsonObject.getString("airZt"))) {
                jsonObject.put("airZt", CodeRepositoryUtil.getValue("AIRZT", jsonObject.getString("airZt")));
            }
            if (StringUtils.isNotEmpty(jsonObject.getString("nature"))) {
                jsonObject.put("nature", CodeRepositoryUtil.getValue("AIRXZ", jsonObject.getString("nature")));
            }
            if(IRoleInfos.toString().indexOf("机务工作人员")>-1){
            	jsonObject.put("roleType", "0");
            }else if("10".equals(cud.getCurrentUnitCode())){
            	jsonObject.put("edit", "0");
            }
        }  
        ResponseMapData resData = new ResponseMapData();
        resData.addResponseData(OBJLIST, jsonArrayObjects);
        resData.addResponseData(PAGE_DESC, pageDesc);

        LayuiResultUtil.layuiwriteResponseDataAsJson(resData, pageDesc, response);
    }

	/**
	 * 查询所有   飞机基础信息  列表
	 *
	 * @param field    json中只保存需要的属性名
	 * @param request  {@link HttpServletRequest}
	 * @param response {@link HttpServletResponse}
	 * @return {data:[]}
	 */
	@RequestMapping(value = "/listNew",method = RequestMethod.GET)
	public void listNew(String[] field, PageDesc pageDesc, HttpServletRequest request, HttpServletResponse response) {
		String limit = request.getParameter("limit");
		if (StringUtils.isBlank(limit)) {
			limit = "10";
		}
		pageDesc.setPageSize(Integer.parseInt(limit));
		Map<String, Object> searchColumn = convertSearchColumn(request);
		searchColumn.put("orderby", " a.INS_TIME DESC ");
		if(searchColumn.get("field")!=null&&StringUtils.isNotBlank(searchColumn.get("field").toString())){
			String orderby=searchColumn.get("field").toString();
			if("endTime".equals(orderby)){
				orderby=" a.END_TIME ";
			}else if("airModel".equals(orderby)){
				orderby=" a.AIR_MODEL ";
			} else if("haveName".equals(orderby)){
				orderby=" a.HAVE_NAME ";
			} else if("ccxlh".equals(orderby)){
				orderby=" TO_NUMBER(a.CCXLH) ";
			}else if("maxZl".equals(orderby)){
				orderby=" a.max_zl ";
			}
			String order=" asc ";
			if(searchColumn.get("order")!=null&&StringUtils.isNotBlank(searchColumn.get("order").toString())){
				order="  "+searchColumn.get("order").toString();
			}
			orderby+=order;
			searchColumn.put("orderby", orderby);
		}
		searchColumn.put("dataValid", "T");
		JSONArray jsonArrayObjects = new JSONArray();
		CentitUserDetails cud = getLoginUser(request);
		List<? extends IRoleInfo> IRoleInfos = cud.getUserRoles();
		jsonArrayObjects = airplaneBaseinfoMag.getAirplaneBaseinfoListNew( searchColumn, pageDesc);
		for (int i = 0; i < jsonArrayObjects.size(); i++) {
			JSONObject jsonObject = jsonArrayObjects.getJSONObject(i);
			if (StringUtils.isNotEmpty(jsonObject.getString("airZt"))) {
				jsonObject.put("airZt", CodeRepositoryUtil.getValue("AIRZT", jsonObject.getString("airZt")));
			}
			if (StringUtils.isNotEmpty(jsonObject.getString("nature"))) {
				jsonObject.put("nature", CodeRepositoryUtil.getValue("AIRXZ", jsonObject.getString("nature")));
			}
			if(IRoleInfos.toString().indexOf("机务工作人员")>-1){
				jsonObject.put("roleType", "0");
			}else if("10".equals(cud.getCurrentUnitCode())){
				jsonObject.put("edit", "0");
			}
		}
		ResponseMapData resData = new ResponseMapData();
		resData.addResponseData(OBJLIST, jsonArrayObjects);
		resData.addResponseData(PAGE_DESC, pageDesc);

		LayuiResultUtil.layuiwriteResponseDataAsJson(resData, pageDesc, response);
	}

	/**
	 * 导出功能
	 * @param
	 * @param
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/listNewImport/{type}",method = RequestMethod.GET)
	public void listNewImport(@PathVariable String type,HttpServletRequest request, HttpServletResponse response) {

		Map<String, Object> searchColumn = convertSearchColumn(request);
		searchColumn.put("orderby", " a.INS_TIME DESC ");
		if(searchColumn.get("field")!=null&&StringUtils.isNotBlank(searchColumn.get("field").toString())){
			String orderby=searchColumn.get("field").toString();
			if("endTime".equals(orderby)){
				orderby=" a.END_TIME ";
			}else if("airModel".equals(orderby)){
				orderby=" a.AIR_MODEL ";
			} else if("haveName".equals(orderby)){
				orderby=" a.HAVE_NAME ";
			} else if("ccxlh".equals(orderby)){
				orderby=" TO_NUMBER(a.CCXLH) ";
			}else if("maxZl".equals(orderby)){
				orderby=" a.max_zl ";
			}
			String order=" asc ";
			if(searchColumn.get("order")!=null&&StringUtils.isNotBlank(searchColumn.get("order").toString())){
				order="  "+searchColumn.get("order").toString();
			}
			orderby+=order;
			searchColumn.put("orderby", orderby);
		}
		searchColumn.put("dataValid", "T");
		JSONArray jsonArrayObjects =  airplaneBaseinfoMag.getAirplaneBaseinfoListNew( searchColumn, null);

		try {
			ExportExcelUtil exportExcelUtil=new ExportExcelUtil();
			switch (type){
				case "sz":
					exportExcelUtil.exportSzb(jsonArrayObjects, "三证表",request,response);
					break;
				case "zlwx":
					exportExcelUtil.exportSzb(jsonArrayObjects, "租赁维修表",request,response);
					break;
					default:
						exportExcelUtil.exportSzb(jsonArrayObjects, "总表",request,response);
						break;
			}

		} catch (Exception e) {
			e.printStackTrace();
		}


	}

	/**
	 * 查询所有   飞机基础信息  列表
	 *
	 * @param field    json中只保存需要的属性名
	 * @param request  {@link HttpServletRequest}
	 * @param response {@link HttpServletResponse}
	 * @return {data:[]}
	 */
	@RequestMapping(value = "/listForYj",method = RequestMethod.GET)
	public void listForYj(String[] field, PageDesc pageDesc, HttpServletRequest request, HttpServletResponse response) {
		String limit = request.getParameter("limit");
		if (StringUtils.isBlank(limit)) {
			limit = "10";
		}
		pageDesc.setPageSize(Integer.parseInt(limit));
		Map<String, Object> searchColumn = convertSearchColumn(request);
		searchColumn.put("dataValid", "T");
		JSONArray jsonArrayObjects = new JSONArray();
		CentitUserDetails cud = getLoginUser(request);
		jsonArrayObjects = airplaneBaseinfoMag.listObjectsAsJson( searchColumn, pageDesc);
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		jsonArrayObjects.stream().forEach(o->{
			JSONObject jsonObject=(JSONObject)o;
			if("预警".equals(jsonObject.getString("tzrqqbnnjhdx"))){
				//间隔时间
				long daysDiff=0;
				try {
					System.out.println("--endTime--"+jsonObject.getDate("endTime"));
					System.out.println("--jhdxxyckssjT--"+jsonObject.getDate("jhdxxyckssjT"));
					LocalDate date1 = LocalDate.parse(sdf.format(jsonObject.getDate("endTime")));
					LocalDate date2 = LocalDate.parse(sdf.format(jsonObject.getDate("jhdxxyckssjT")));
					daysDiff = ChronoUnit.DAYS.between(date1, date2);
					System.out.println("--1111--"+daysDiff);
				}catch (Exception e){
					e.printStackTrace();
				}

				jsonObject.put("tzrqqbnnjhdxDays",daysDiff);
			}else {
				jsonObject.put("tzrqqbnnjhdxDays","");
			}
			if("预警".equals(jsonObject.getString("tzrqqbnnyqdx"))){
				long daysDiff=0;
				try {
					System.out.println("--endTime--"+jsonObject.getDate("endTime"));
					System.out.println("--dxksslQ1--"+jsonObject.getDate("dxksslQ1"));
					LocalDate date1 = LocalDate.parse(sdf.format(jsonObject.getDate("endTime")));
					LocalDate date2 = LocalDate.parse(sdf.format(jsonObject.getDate("dxksslQ1")));
					daysDiff = ChronoUnit.DAYS.between(date1, date2);

					System.out.println("--1111--"+daysDiff);
				}catch (Exception e){
					e.printStackTrace();
				}

				jsonObject.put("tzrqqbnnyqdxDays",daysDiff);

			}else {
				jsonObject.put("tzrqqbnnyqdxDays","");
			}

		});

		//计算电台执照到期时间
		if("dtzz".equals(searchColumn.get("dtzzDq"))){
			JSONArray newJson=new JSONArray();
			Calendar calendar=Calendar.getInstance();
			calendar.add(Calendar.DATE,-90);//往前推90天
			searchColumn.put("dtzzjkbjrq",sdf.format(calendar.getTime()));

			newJson = airplaneBaseinfoMag.listObjectsAsJson( searchColumn, pageDesc);


			newJson.stream().forEach(o->{
				JSONObject jsonObject=(JSONObject)o;
				long daysDiff=61;
				try {
					Date today=new Date();
					jsonObject.put("dtzzjkbjDate",sdf.format(jsonObject.getDate("dtzzjkbjrq")));
					LocalDate date2 = LocalDate.parse(sdf.format(today));
					LocalDate date1 = LocalDate.parse(sdf.format(jsonObject.getDate("dtzzjkbjrq")));
					daysDiff = ChronoUnit.DAYS.between(date2, date1);

				}catch (Exception e){
					e.printStackTrace();
					daysDiff=91l;
				}

				if(daysDiff<90l){
					jsonObject.put("dtzzDqsj",daysDiff);
				}
			});
			jsonArrayObjects=newJson;

		}

		ResponseMapData resData = new ResponseMapData();
		resData.addResponseData(OBJLIST, jsonArrayObjects);
		resData.addResponseData(PAGE_DESC, pageDesc);

		LayuiResultUtil.layuiwriteResponseDataAsJson(resData, pageDesc, response);
	}

	/**
	 * 查询所有   飞机基础信息  列表
	 *
	 * @param field    json中只保存需要的属性名
	 * @param request  {@link HttpServletRequest}
	 * @param response {@link HttpServletResponse}
	 * @return {data:[]}
	 */
	@RequestMapping(value = "/listForYj2",method = RequestMethod.GET)
	public void listForYj2(String[] field, PageDesc pageDesc, HttpServletRequest request, HttpServletResponse response) {
		String limit = request.getParameter("limit");
		if (StringUtils.isBlank(limit)) {
			limit = "10";
		}
		pageDesc.setPageSize(Integer.parseInt(limit));
		JSONArray jsonArrayObjects = allData(request.getParameter("searchType"),pageDesc);
		ResponseMapData resData = new ResponseMapData();
		resData.addResponseData(OBJLIST, jsonArrayObjects);
		resData.addResponseData(PAGE_DESC, pageDesc);

		LayuiResultUtil.layuiwriteResponseDataAsJson(resData, pageDesc, response);
	}

	private JSONArray allData(String type,PageDesc pageDesc){
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		if("jhdx".equals(type)){
			Map<String, Object> searchColumn =new HashMap<>();
			searchColumn.put("dataValid", "T");
			searchColumn.put("tzrqqbnnjhdx", "预警");
			JSONArray jsonArrayObjects = airplaneBaseinfoMag.listObjectsAsJson(searchColumn, pageDesc);

			jsonArrayObjects.stream().forEach(o->{
				JSONObject jsonObject=(JSONObject)o;
				//间隔时间
				long daysDiff=0;
				try {
					LocalDate date2 = LocalDate.parse(sdf.format(jsonObject.getDate("endTime")));
					LocalDate date1 = LocalDate.parse(sdf.format(jsonObject.getDate("jhdxxyckssjT")));
					daysDiff = ChronoUnit.DAYS.between(date1, date2);
				}catch (Exception e){
					e.printStackTrace();
				}

				jsonObject.put("tzrqqbnnjhdxDays",daysDiff);
			});

			return jsonArrayObjects;
		}else if("yqdx".equals(type)){
			Map<String, Object> searchColumn =new HashMap<>();
			searchColumn.put("dataValid", "T");
			searchColumn.put("tzrqqbnnyqdx", "预警");
			JSONArray jsonArrayObjects = airplaneBaseinfoMag.listObjectsAsJson(searchColumn, pageDesc);

			jsonArrayObjects.stream().forEach(o->{
				JSONObject jsonObject=(JSONObject)o;
				//间隔时间
				long daysDiff=0;
				long daysDiff2=0;
				try {
					LocalDate date1 = LocalDate.parse(sdf.format(jsonObject.getDate("endTime")));
					LocalDate date2 = LocalDate.parse(sdf.format(jsonObject.getDate("dxksslQ1")));
					LocalDate date3 = LocalDate.parse(sdf.format(jsonObject.getDate("dxkssjQ2")));
					daysDiff = ChronoUnit.DAYS.between(date2,date1);
					daysDiff2 = ChronoUnit.DAYS.between(date3,date1);
				}catch (Exception e){
					e.printStackTrace();
				}

				jsonObject.put("tzrqqbnnyqdxDays",daysDiff+","+daysDiff2);
			});

			return jsonArrayObjects;
		}else {
			//默认电台执照
			Map<String, Object> searchColumn =new HashMap<>();
			searchColumn.put("dataValid", "T");
			Date today=new Date();
			searchColumn.put("dtzzjkbjrq",sdf.format(today));

			JSONArray newJson= airplaneBaseinfoMag.listObjectsAsJson( searchColumn, pageDesc);


			newJson.stream().forEach(o->{
				JSONObject jsonObject=(JSONObject)o;
				long daysDiff=0;
				try {

					jsonObject.put("dtzzjkbjDate",sdf.format(jsonObject.getDate("dtzzjkbjrq")));
					LocalDate date2 = LocalDate.parse(sdf.format(today));
					LocalDate date1 = LocalDate.parse(sdf.format(jsonObject.getDate("dtzzjkbjrq")));
					daysDiff = ChronoUnit.DAYS.between(date1, date2);

				}catch (Exception e){
					e.printStackTrace();
					daysDiff=0l;
				}

				jsonObject.put("dtzzDqsj",daysDiff);

			});
			System.out.println("--------newJson-------"+ JSON.toJSONString(newJson));
			return newJson;
		}

	}


	@RequestMapping(value = "/closeSms/{recId}", method = {RequestMethod.PUT})
	public void closeSms(@PathVariable String recId,
							   @Valid AirplaneBaseinfo airplaneBaseinfo, HttpServletResponse response, HttpServletRequest request) {
		CentitUserDetails cud = getLoginUser(request);
		AirplaneBaseinfo airplaneBaseinfo1=airplaneBaseinfoMag.getObjectById(recId);


		JsonResultUtils.writeSingleDataJson("操作成功",response);
	}


    
    /**
     * 查询所有   飞机基础信息  列表
     *
     * @param field    json中只保存需要的属性名
     * @param request  {@link HttpServletRequest}
     * @param response {@link HttpServletResponse}
     * @return {data:[]}
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public void bglist(String[] field, PageDesc pageDesc, HttpServletRequest request, HttpServletResponse response) {
    	String limit = request.getParameter("limit");
        if (StringUtils.isBlank(limit)) {
            limit = "10";
        }
        pageDesc.setPageSize(Integer.parseInt(limit));
    	Map<String, Object> searchColumn = convertSearchColumn(request);        
    	searchColumn.put("dataValid", "T");
    	searchColumn.put("airZt", "2");
    	JSONArray jsonArrayObjects = new JSONArray();
    	CentitUserDetails cud = getLoginUser(request);
		List<? extends IRoleInfo> IRoleInfos = cud.getUserRoles();
		jsonArrayObjects = airplaneBaseinfoMag.listObjectsAsJson( searchColumn, pageDesc);
        for (int i = 0; i < jsonArrayObjects.size(); i++) {
            JSONObject jsonObject = jsonArrayObjects.getJSONObject(i);
            if (StringUtils.isNotEmpty(jsonObject.getString("airZt"))) {
                jsonObject.put("airZt", CodeRepositoryUtil.getValue("AIRZT", jsonObject.getString("airZt")));
            }
            if (StringUtils.isNotEmpty(jsonObject.getString("nature"))) {
                jsonObject.put("nature", CodeRepositoryUtil.getValue("AIRXZ", jsonObject.getString("nature")));
            }
            if(IRoleInfos.toString().indexOf("机务工作人员")>-1){
            	jsonObject.put("roleType", "0");
            }else if("10".equals(cud.getCurrentUnitCode())){
            	jsonObject.put("edit", "0");
            }
        }  
        ResponseMapData resData = new ResponseMapData();
        resData.addResponseData(OBJLIST, jsonArrayObjects);
        resData.addResponseData(PAGE_DESC, pageDesc);

        LayuiResultUtil.layuiwriteResponseDataAsJson(resData, pageDesc, response);
    }
    
    /**
	 * 打开编辑单个
	 *
	 * @param recId
	 *            recId
	 *
	 * @param response
	 *            {@link HttpServletResponse}
	 * @return forward
	 */
	@RequestMapping(value = "/{recId}/{type}", method = { RequestMethod.GET })
	public ModelAndView toAzdbqry(@PathVariable String recId,@PathVariable String type,
			HttpServletResponse response, HttpServletRequest request) {
		ModelAndView mv = new ModelAndView();
		CentitUserDetails cud = getLoginUser(request);
		List<? extends IRoleInfo> IRoleInfos = cud.getUserRoles();
		/*ztx11.15改：不在根据权限拆分页面。直接汇总所有字段*/
		String forward = "forward:/modules/airplanebaseinfo/airplanebaseinfo/all/airplanebaseinfo-allinfo.jsp";
		AirplaneBaseinfo airplaneBaseinfo =
				airplaneBaseinfoMag.getObjectById( recId);
		if(airplaneBaseinfo==null){
			airplaneBaseinfo = new AirplaneBaseinfo();
		}
		if ("view".equals(type)) {
			forward = "forward:/modules/airplanebaseinfo/airplanebaseinfo/all/airplanebaseinfo-all-view.jsp";
		}else if("edit".equals(type)){
			forward = "forward:/modules/airplanebaseinfo/airplanebaseinfo/all/airplanebaseinfo-allinfo.jsp";
		}
		//String forward = "forward:/modules/airplanebaseinfo/airplanebaseinfo/airplanebaseinfo-info.jsp";
		/*if(IRoleInfos.toString().indexOf("机务工作人员")>-1){
			forward = "forward:/modules/airplanebaseinfo/airplanebaseinfo/airplanebaseinfo-jwinfo.jsp";
		}
		AirplaneBaseinfo airplaneBaseinfo =     			
    			airplaneBaseinfoMag.getObjectById( recId);
		if(airplaneBaseinfo==null){
			airplaneBaseinfo = new AirplaneBaseinfo();
		}
		if ("view".equals(type)) {
				forward = "forward:/modules/airplanebaseinfo/airplanebaseinfo/airplanebaseinfo-view.jsp";
		}else if("uphold".equals(type)){
			forward = "forward:/modules/airplanebaseinfo/airplanebaseinfo/airplanebaseinfo-jwinfo.jsp";
		}else if("bg".equals(type)){
			String logId = request.getParameter("logId");
			mv.addObject("logId", logId);
			if(IRoleInfos.toString().indexOf("规划发展部")>-1){
				forward = "forward:/modules/airplanebaseinfo/airplanebaseinfo/airplanebaseinfo-ghinfo.jsp";
			}else if(IRoleInfos.toString().indexOf("财务会计部")>-1){
				forward = "forward:/modules/airplanebaseinfo/airplanebaseinfo/airplanebaseinfo-cwinfo.jsp";
			}
		}else if("openDb".equals(type)){
			IUnitInfo unit=CodeRepositoryUtil.getUnitInfoByCode(cud.getCurrentUnitCode());
			String unitName=unit.getUnitName();
			forward = "forward:/modules/airplanebaseinfo/oa/airplanebaseinfoBL.jsp";
			JSONObject ideaInfo=ideaInfoMag.getLastIdeaInfo(airplaneBaseinfo.getFlowInsId());
			if(ideaInfo!=null){
				mv.addObject("ideaType", ideaInfo.getString("ideaType"));
			}
			mv.addObject("unitCode", unit.getUnitCode());
			//判断部门 显示不同待办页面
		}*/else{
			 Date currentTime = new Date();
			 SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			 String dateString = formatter.format(currentTime);
			 airplaneBaseinfo.setDjsj(dateString);
		}
		mv.addObject(OBJECT, airplaneBaseinfo);
		mv.setViewName(forward);
		return mv;
	}
	
	 /**
     * 获取日志信息
     */
    @RequestMapping(value = "/checkAirplane", method = {RequestMethod.POST})
    public void checkAirplane(HttpServletRequest request, HttpServletResponse response) {
    	String recId=request.getParameter("recId");
    	if(recId!=null&&StringUtils.isNotBlank(recId)){
    		AirplaneBaseinfo airplaneBaseinfo =     			
        			airplaneBaseinfoMag.getObjectById( recId);
    		String result=airplaneBaseinfo.checkField(airplaneBaseinfo);
    		 JsonResultUtils.writeSingleDataJson(result,response);
    	}
    }
	
	
	 /**
     * 获取日志信息
     */
    @RequestMapping(value = "/listIdeaInfo", method = {RequestMethod.GET})
    public void listIdeaInfo(PageDesc pageDesc, HttpServletRequest request, HttpServletResponse response) {
    	 Map<String, Object> searchColumn = convertSearchColumn(request);
    	 searchColumn.put("dataValid", "T");
    	 searchColumn.put(CodeBook.SELF_ORDER_BY, "create_time asc");
    	 JSONArray jsonArrayObjects = ideaInfoMag.listIdeaInfo(searchColumn, null);
         
    	 ResponseMapData resData = new ResponseMapData();
         resData.addResponseData(OBJLIST, jsonArrayObjects);
         resData.addResponseData(PAGE_DESC, pageDesc);
         LayuiResultUtil.layuiwriteResponseDataAsJson(resData, pageDesc, response);
    }
    /**
     * 获取办理界面
     * @param request
     * @param response
     */
    @RequestMapping(value = "/getBlPage", method = {RequestMethod.GET})
    public void getBlPage( HttpServletRequest request, HttpServletResponse response) {
    	CentitUserDetails cud = getLoginUser(request);
    	
    	String unitCode=cud.getCurrentUnitCode();
    	String recId=request.getParameter("recId");
    	AirplaneBaseinfo module=airplaneBaseinfoMag.getObjectById(recId);
    	JSONObject o=ideaInfoMag.getLastIdeaInfo(module.getFlowInsId());
    	String status="1";
    	if(o!=null){
    		if("飞机引进计划".equals(o.getString("ideaType"))){
    			status="1";
    		}else if("日常维护变更".equals(o.getString("ideaType"))){
    			status="2";
    		}
    	}
    	
    	String pageUrl="";
    	switch (unitCode) {
			case "10":
				if("1".equals(status)){
					pageUrl="/dhjdglxt/service/airplanebaseinfo/airplanebaseinfo/oa/flowedit";
				}else{
					pageUrl="/dhjdglxt/service/airplanebaseinfo/airplanebaseinfo/oa/cz";
				}
				break;
			case "11":
				pageUrl="/dhjdglxt/service/airplanebaseinfo/airplanebaseinfo/oa/jwadd";
				break;
			case "12":
				if("1".equals(status)){
					pageUrl="/dhjdglxt/service/airplanebaseinfo/airplanebaseinfo/oa/cwadd";
		    	}else{
					pageUrl="/dhjdglxt/service/airplanebaseinfo/airplanebaseinfo/oa/cz";
				}
				break;
			case "13":
				pageUrl="/dhjdglxt/service/airplanebaseinfo/airplanebaseinfo/oa/floweditpw";
				break;
			case "14":
				if("1".equals(status)){
					pageUrl="/dhjdglxt/service/airplanebaseinfo/airplanebaseinfo/oa/jwadd";
				}else{
					//三证有效性维护
					pageUrl="/dhjdglxt/service/airplanebaseinfo/airplanebaseinfo/szinfo";
				}
				break;
			case "15":
				pageUrl="/dhjdglxt/service/airplanebaseinfo/airplanebaseinfo/oa/flowedit";
				break;
			case "16":
				pageUrl="/dhjdglxt/service/airplanebaseinfo/airplanebaseinfo/oa/flowedit";
				break;
			case "17":
				pageUrl="/dhjdglxt/service/airplanebaseinfo/airplanebaseinfo/oa/flowedit";
				break;
			default:
				break;
		}
    	   JsonResultUtils.writeSingleDataJson(pageUrl,response);
    }
    /**
     * 查询单个  飞机基础信息 
	
	 * @param recId  REC_ID
     *  
     * 
     * @param response    {@link HttpServletResponse}
     * @return {data:{}}
     */
    @RequestMapping(value = "/{recId}", method = {RequestMethod.GET})
    public void getAirplaneBaseinfo(@PathVariable String recId, HttpServletResponse response) {
    	
    	AirplaneBaseinfo airplaneBaseinfo =     			
    			airplaneBaseinfoMag.getObjectById( recId);
        
        JsonResultUtils.writeSingleDataJson(airplaneBaseinfo, response);
    }
    
    /**
     * 新增 飞机基础信息，业务只有新增的时候可用此方法，如有修改可用下面 新增或保存合并的方法
     *
     * @param airplaneBaseinfo  {@link AirplaneBaseinfo}
     * @return
     */
    @RequestMapping(method = {RequestMethod.POST})
    public void createAirplaneBaseinfo(@Valid AirplaneBaseinfo airplaneBaseinfo, HttpServletResponse response) {
    	 airplaneBaseinfoMag.saveNewObject(airplaneBaseinfo);
        JsonResultUtils.writeSingleDataJson("操作成功",response);
    }

    /**
     * 获取待办列表
     */
    @RequestMapping(value = "/listDb", method = {RequestMethod.GET})
    public void listApplyDb(PageDesc pageDesc, HttpServletRequest request, HttpServletResponse response) {
         Map<String, Object> searchColumn = convertSearchColumn(request);
    	 CentitUserDetails loginUser = getLoginUser(request);
    	 
    	 searchColumn.put("dataValid", "T");
    	 searchColumn.put("userCode", loginUser.getUserCode());
    	
    	
    	 JSONArray jsonArrayObjects = airplaneBaseinfoMag.listDb(searchColumn, pageDesc);
    	   for (int i = 0; i < jsonArrayObjects.size(); i++) {
               JSONObject jsonObject = jsonArrayObjects.getJSONObject(i);
               if (StringUtils.isNotEmpty(jsonObject.getString("airZt"))) {
                   jsonObject.put("airZt", CodeRepositoryUtil.getValue("AIRZT", jsonObject.getString("airZt")));
               }
               if (StringUtils.isNotEmpty(jsonObject.getString("nature"))) {
                   jsonObject.put("nature", CodeRepositoryUtil.getValue("AIRXZ", jsonObject.getString("nature")));
               }
           }  
    	 ResponseMapData resData = new ResponseMapData();
         resData.addResponseData(OBJLIST, jsonArrayObjects);
         resData.addResponseData(PAGE_DESC, pageDesc);
         LayuiResultUtil.layuiwriteResponseDataAsJson(resData, pageDesc, response);
    }
    
    /**
     * 删除单个  飞机基础信息 
	
	 * @param recId  REC_ID
     */
    @RequestMapping(value = "/{recId}", method = {RequestMethod.DELETE})
    public void deleteAirplaneBaseinfo(@PathVariable String recId, HttpServletResponse response, HttpServletRequest request) {
    	CentitUserDetails cud = getLoginUser(request);
    	
    	AirplaneBaseinfo dbAirplaneBaseinfo  =     			
    			airplaneBaseinfoMag.getObjectById( recId);
    	
    	dbAirplaneBaseinfo.setDataValid("F");
    	dbAirplaneBaseinfo.setDelTime(new Date());
    	dbAirplaneBaseinfo.setDelUsercode(cud.getUserCode());
    	airplaneBaseinfoMag.mergeObject(dbAirplaneBaseinfo);
        JsonResultUtils.writeSingleDataJson("操作成功",response);
    } 
    
    @RequestMapping(value = "/uphold/{recId}", method = {RequestMethod.PUT})
    public void upholdAirplaneBaseinfo(@PathVariable String recId, 
    	@Valid AirplaneBaseinfo airplaneBaseinfo, HttpServletResponse response, HttpServletRequest request) {
    	CentitUserDetails cud = getLoginUser(request);
    	
    	AirplaneBaseinfo dbAirplaneBaseinfo  =     			
    			airplaneBaseinfoMag.getObjectById( recId);
    	  if (null != dbAirplaneBaseinfo) {
	    	IUserInfo user= CodeRepositoryUtil.getUserInfoByCode(cud.getUserCode());
	    	IUnitInfo unitInfo= CodeRepositoryUtil.getUnitInfoByCode(cud.getCurrentUnitCode());
	    	
	    	String upholdInfo=dbAirplaneBaseinfo.getCopyInfo(airplaneBaseinfo);
	    	if(StringUtils.isNotBlank(upholdInfo)){
	    		String ideaRecId=UuidOpt.getUuidAsString32();
		    	IdeaInfo ideaInfo=new IdeaInfo(ideaRecId,"",user,unitInfo,"已办",new Date(),dbAirplaneBaseinfo.getRecId(),"飞机信息维护");
		    	ideaInfo.setContent(upholdInfo);
		    	ideaInfoMag.saveNewObject(ideaInfo);
	    	}
	    	
	    	dbAirplaneBaseinfo.copyNotNullProperty(airplaneBaseinfo);//赋值页面不为空的值，小心页面空的字符串或者改写copyNotNullProperty方法，根据自己业务需要
	    	dbAirplaneBaseinfo.setEditUsercode(cud.getUserCode());
	    	dbAirplaneBaseinfo.setEditTime(new Date());
	    	airplaneBaseinfoMag.mergeObject(dbAirplaneBaseinfo);
    	  }
    	JsonResultUtils.writeSingleDataJson("操作成功",response);
    }
    
    /**
     * 新增或保存 飞机基础信息 
    
	 * @param recId  REC_ID
	 * @param airplaneBaseinfo  {@link AirplaneBaseinfo}
     * @param response    {@link HttpServletResponse}
     */
    @RequestMapping(value = "/{recId}", method = {RequestMethod.PUT})
    public void updateAirplaneBaseinfo(@PathVariable String recId, 
    	@Valid AirplaneBaseinfo airplaneBaseinfo, HttpServletResponse response, HttpServletRequest request) {
    	CentitUserDetails cud = getLoginUser(request);
    	
    	AirplaneBaseinfo dbAirplaneBaseinfo  =     			
    			airplaneBaseinfoMag.getObjectById( recId);
        if (null != dbAirplaneBaseinfo) {//如果数据库数据存在，则是更新操作
        	dbAirplaneBaseinfo .copyNotNullProperty(airplaneBaseinfo);//赋值页面不为空的值，小心页面空的字符串或者改写copyNotNullProperty方法，根据自己业务需要
        	dbAirplaneBaseinfo.setEditUsercode(cud.getUserCode());
        	dbAirplaneBaseinfo.setEditTime(new Date());
			dbAirplaneBaseinfo=dbAirplaneBaseinfo.calculatedValue(dbAirplaneBaseinfo);
        	if(airplaneBaseinfo.getStatus()!=null&&airplaneBaseinfo.getStatus().equals("1")){
        		dbAirplaneBaseinfo.setAirZt("1");
        		dbAirplaneBaseinfo.setStatus("1");
            	System.out.println("启动流程****************************************");
            	String jhId = airplaneBaseinfo.getGljh();
            	//String jhName = jdghglMag.getObjectById(jhId).getGhName();
            	String flowRecId=UuidOpt.getUuidAsString32();
            	dbAirplaneBaseinfo.setFlowInsId(flowRecId);
            	String ideaRecId=UuidOpt.getUuidAsString32();
            	String nextUserId=request.getParameter("nextUser");
            	IUserInfo user= CodeRepositoryUtil.getUserInfoByCode(cud.getUserCode());
            	IUnitInfo unitInfo= CodeRepositoryUtil.getUnitInfoByCode(cud.getCurrentUnitCode());
            	IUserInfo nextUser= CodeRepositoryUtil.getUserInfoByCode(nextUserId);
            	IUnitInfo nextUnit= CodeRepositoryUtil.getUnitInfoByCode(nextUser.getPrimaryUnit());
            	//新增日志
            	IdeaInfo ideaInfo=new IdeaInfo(ideaRecId,flowRecId,user,unitInfo,"已办",new Date(),dbAirplaneBaseinfo.getRecId(),"飞机引进计划");
            	ideaInfoMag.saveNewObject(ideaInfo);
            	IdeaInfo ideaNext=new IdeaInfo(UuidOpt.getUuidAsString32(),flowRecId,nextUser,nextUnit,"待办理",null,dbAirplaneBaseinfo.getRecId(),"飞机引进计划");
            	ideaInfoMag.saveNewObject(ideaNext);
            	
            	
            	//新增节点信息
            	FlowNode node=new FlowNode();
            	node.setFlowRecId(flowRecId);
            	node.setRecId(UuidOpt.getUuidAsString32());
            	node.setIdeaRecId(ideaRecId);
            	node.setStatus("N");
            	node.setNodeName("飞机引进计划");
            	node.setNodeNum(1);
            	node.setNextUserCode(nextUserId);
            	node.setNextUserUnit(nextUnit.getUnitCode());
            	node.setStatus("N");
            	flowNodeMag.saveNewObject(node);
            	/*try {
    			FlowInstance flowInstance =	flowEngineClient.createInstanceLockFirstNode("262", jhName, dbAirplaneBaseinfo.getRecId(), cud.getUserCode(), cud.getCurrentUnitCode());
    			if(flowInstance!=null){
    				Long flowInstId = flowInstance.getFlowInstId();
    				List<String> userCodeSet =new ArrayList<String>();
    				userCodeSet.add(cud.getUserCode());
    				flowEngineClient.assignFlowWorkTeam(flowInstId, "operator", userCodeSet);//添加经办人
    				//flowEngineClient.saveFlowVariable(flowInstId, "fjxz", airplaneBaseinfo.getNature());
    				airplaneBaseinfoMag.insertFlow(flowInstId, "fjxz", airplaneBaseinfo.getNature());
    				flowEngineClient.submitOpt(flowInstance.getFirstNodeInstance().getNodeInstId(), cud.getUserCode(), cud.getCurrentUnitCode(), null, null);
    				NodeInstance nodeInstance = 	flowInstance.getFirstNodeInstance();
    				Long nodeInstId =  nodeInstance.getNodeInstId();
    				String nodeCode = nodeInstance.getNodeCode();
    				//保存流程日志
    				airplaneBaseinfoMag.insertFlowLog(UuidOpt.getUuidAsString32(), flowInstId, nodeInstId, cud.getCurrentUnitCode(), cud.getUserCode(), new Date(), "计划飞机引进", nodeCode);
    				dbAirplaneBaseinfo.setFlowInsId(flowInstId+"");
    			}
            	} catch (Exception e) {
    				e.printStackTrace();
    			}*/
            }
        	airplaneBaseinfoMag.mergeObject(dbAirplaneBaseinfo);
        } else {
        	airplaneBaseinfo.setRecId(UuidOpt.getUuidAsString32());
            airplaneBaseinfo.setDataValid("T");
            airplaneBaseinfo.setInsTime(new Date());
            airplaneBaseinfo.setInsUsercode(cud.getUserCode());
            if(StringUtils.isNoneBlank(airplaneBaseinfo.getStatus())&&airplaneBaseinfo.getStatus().equals("1")){
            	airplaneBaseinfo.setStatus("1");
            }else{
            	airplaneBaseinfo.setStatus("0");
            }
            if(airplaneBaseinfo.getStatus()!=null&&airplaneBaseinfo.getStatus().equals("1")){
        		airplaneBaseinfo.setAirZt("1");
            	System.out.println("启动流程****************************************");
            	String jhId = airplaneBaseinfo.getGljh();
            	//String jhName = jdghglMag.getObjectById(jhId).getGhName();
            	String flowRecId=UuidOpt.getUuidAsString32();
            	airplaneBaseinfo.setFlowInsId(flowRecId);
            	String ideaRecId=UuidOpt.getUuidAsString32();
            	String nextUserId=request.getParameter("nextUser");
            	IUserInfo user= CodeRepositoryUtil.getUserInfoByCode(cud.getUserCode());
            	IUnitInfo unitInfo= CodeRepositoryUtil.getUnitInfoByCode(cud.getCurrentUnitCode());
            	IUserInfo nextUser= CodeRepositoryUtil.getUserInfoByCode(nextUserId);
            	IUnitInfo nextUnit= CodeRepositoryUtil.getUnitInfoByCode(nextUser.getPrimaryUnit());
            	//新增日志
            	IdeaInfo ideaInfo=new IdeaInfo(ideaRecId,flowRecId,user,unitInfo,"已办",new Date(),airplaneBaseinfo.getRecId(),"飞机引进计划");
            	ideaInfoMag.saveNewObject(ideaInfo);
            	IdeaInfo ideaNext=new IdeaInfo(UuidOpt.getUuidAsString32(),flowRecId,nextUser,nextUnit,"待办理",null,airplaneBaseinfo.getRecId(),"飞机引进计划");
            	ideaInfoMag.saveNewObject(ideaNext);
            	
            	
            	//新增节点信息
            	FlowNode node=new FlowNode();
            	node.setFlowRecId(flowRecId);
            	node.setRecId(UuidOpt.getUuidAsString32());
            	node.setIdeaRecId(ideaRecId);
            	node.setStatus("N");
            	node.setNodeName("计划飞机引进");
            	node.setNodeNum(1);
            	node.setNextUserCode(nextUserId);
            	node.setNextUserUnit(nextUnit.getUnitCode());
            	node.setStatus("N");
            	flowNodeMag.saveNewObject(node);
            	/*try {
    			FlowInstance flowInstance =	flowEngineClient.createInstanceLockFirstNode("262", jhName, airplaneBaseinfo.getRecId(), cud.getUserCode(), cud.getCurrentUnitCode());
    			if(flowInstance!=null){
    				Long flowInstId = flowInstance.getFlowInstId();
    				List<String> userCodeSet =new ArrayList<String>();
    				userCodeSet.add(cud.getUserCode());
    				flowEngineClient.assignFlowWorkTeam(flowInstId, "operator", userCodeSet);//添加经办人
    				//flowEngineClient.saveFlowVariable(flowInstId, "fjxz", airplaneBaseinfo.getNature());
    				airplaneBaseinfoMag.insertFlow(flowInstId, "fjxz", airplaneBaseinfo.getNature());
    				flowEngineClient.submitOpt(flowInstance.getFirstNodeInstance().getNodeInstId(), cud.getUserCode(), cud.getCurrentUnitCode(), null, null);
    				NodeInstance nodeInstance = 	flowInstance.getFirstNodeInstance();
    				Long nodeInstId =  nodeInstance.getNodeInstId();
    				String nodeCode = nodeInstance.getNodeCode();
    				//保存流程日志
    				airplaneBaseinfoMag.insertFlowLog(UuidOpt.getUuidAsString32(), flowInstId, nodeInstId, cud.getCurrentUnitCode(), cud.getUserCode(), new Date(), "计划飞机引进", nodeCode);
    				airplaneBaseinfo.setFlowInsId(flowInstId+"");
    			}
            	} catch (Exception e) {
    				e.printStackTrace();
    			}*/
            }
            airplaneBaseinfo=airplaneBaseinfo.calculatedValue(airplaneBaseinfo);
            airplaneBaseinfoMag.saveNewObject(airplaneBaseinfo);//新增,注意主键赋值 UuidUtil.getTimeBasedUuid()，填写自己的业务时间，业务操作人等信息	
        }
        JsonResultUtils.writeSingleDataJson("操作成功",response);
    }
    
    /**
     * 流程提交
     * @param request
     * @param response
     * @throws ParseException
     */
    @RequestMapping(value = "/submitFlow",method = RequestMethod.POST)
    public void submitFlow(@Valid AirplaneBaseinfo airplaneBaseinfo, HttpServletRequest request, HttpServletResponse response) throws ParseException {
	   	 String content=request.getParameter("transContent");
	   	 String nextUserId=request.getParameter("nextUser");
	   	 String nextUserName=request.getParameter("nextUserName");
	   	 String flowRecId=request.getParameter("flowRecId");
	   	 if(nextUserId!=null&&StringUtils.isNotBlank(nextUserId)&&airplaneBaseinfo!=null){
	   		CentitUserDetails cud = getLoginUser(request);
	   		String flowState=request.getParameter("flowState");
	   		//将待办理改为已办
	   		ideaInfoMag.updateLastIdeaInfo(flowRecId, cud.getUserCode(), content);
	   		//修改办理人节点信息
	   		flowNodeMag.updateFlowNodeStatus(flowRecId, cud.getUserCode());
	   		
	   		IUserInfo nextUser= CodeRepositoryUtil.getUserInfoByCode(nextUserId);
        	IUnitInfo nextUnit= CodeRepositoryUtil.getUnitInfoByCode(nextUser.getPrimaryUnit());
        	String ideaRecId=UuidOpt.getUuidAsString32();
	   		
        	
        	 	JSONObject obj=ideaInfoMag.getLastIdeaInfo(flowRecId);
	   			//新增下一个人办理日志
	   			IdeaInfo ideaNext=new IdeaInfo(ideaRecId,flowRecId,nextUser,nextUnit,"待办理",null,airplaneBaseinfo.getRecId(),obj==null?"":obj.getString("ideaType"));
	        	ideaInfoMag.saveNewObject(ideaNext);
	        	
	        	//新增下一个办理人信息
		   		Integer maxNum=flowNodeMag.getMaxNum(flowRecId);	   		
		   		FlowNode node=new FlowNode();
	        	node.setFlowRecId(flowRecId);
	        	node.setRecId(UuidOpt.getUuidAsString32());
	        	node.setIdeaRecId(ideaRecId);
	        	node.setStatus("N");
	        	node.setNodeName("");
	        	node.setNodeNum(maxNum+1);
	        	node.setNextUserCode(nextUserId);
	        	node.setNextUserUnit(nextUnit.getUnitCode());
	        	node.setStatus("N");
	        	flowNodeMag.saveNewObject(node);
	   	 }else{
	   		CentitUserDetails cud = getLoginUser(request);
	   		String flowState=request.getParameter("flowState");
	   		airplaneBaseinfo=airplaneBaseinfoMag.getObjectById(airplaneBaseinfo.getRecId());
	   		//将待办理改为已办
	   		ideaInfoMag.updateLastIdeaInfo(flowRecId, cud.getUserCode(), content);
	   		//修改办理人节点信息
	   		flowNodeMag.updateFlowNodeStatus(flowRecId, cud.getUserCode());
	   		if("End".equals(flowState)){
	   			airplaneBaseinfo=airplaneBaseinfoMag.getObjectById(airplaneBaseinfo.getRecId());
	   			airplaneBaseinfo.setStatus("2");//流程结束 使用
	    		airplaneBaseinfo.setAirZt("2");
	    		airplaneBaseinfoMag.mergeObject(airplaneBaseinfo);
	   		}else{
	   			
	   			airplaneBaseinfo.setStatus("2");//流程结束 注销
	   			if(airplaneBaseinfo.getCzType()==null||StringUtils.isBlank(airplaneBaseinfo.getCzType())){
	   				airplaneBaseinfo.setAirZt("2");
	   			}else{
	   				airplaneBaseinfo.setStatus("3");
	   				airplaneBaseinfo.setAirZt("3");
	   			}
         		airplaneBaseinfo.setOffDate(new Date());
         		airplaneBaseinfoMag.mergeObject(airplaneBaseinfo);
	   		}
	   	 }
	     JsonResultUtils.writeSingleDataJson("操作成功",response);
    } 
    
    /**
     * 变更 飞机基础信息 
    
	 * @param recId  REC_ID
	 * @param airplaneBaseinfo  {@link AirplaneBaseinfo}
     * @param response    {@link HttpServletResponse}
     */
    @RequestMapping(value = "/savebg/{bgtype}/{recId}", method = {RequestMethod.PUT})
    public void bgAirplaneBaseinfo(@PathVariable String bgtype,@PathVariable String recId, 
    	@Valid AirplaneBaseinfo airplaneBaseinfo, HttpServletResponse response, HttpServletRequest request) {
    	CentitUserDetails cud = getLoginUser(request);
    	
    	AirplaneBaseinfo dbAirplaneBaseinfo  =     			
    			airplaneBaseinfoMag.getObjectById( recId);
    	
        if (null != dbAirplaneBaseinfo) {//如果数据库数据存在，则是更新操作
        	dbAirplaneBaseinfo .copyNotNullProperty(airplaneBaseinfo);//赋值页面不为空的值，小心页面空的字符串或者改写copyNotNullProperty方法，根据自己业务需要
        	dbAirplaneBaseinfo.setEditUsercode(cud.getUserCode());
        	dbAirplaneBaseinfo.setEditTime(new Date());
        	dbAirplaneBaseinfo.setStatus("1");
        	String logId = request.getParameter("logId");
        	if(StringUtils.isNotBlank(logId)){
        		jddtDtjktxlogManager.handle(logId);
        	}
            try {
            	if(StringUtils.isNoneBlank(bgtype)){
            		String name = "融资、出租人变更";
            		if(!bgtype.equals("1")){
            			 name = "占有权及IDERA办理";
            		}
                 	String flowRecId=UuidOpt.getUuidAsString32();
                	airplaneBaseinfo.setFlowInsId(flowRecId);
                	dbAirplaneBaseinfo.setFlowInsId(flowRecId);
                	String ideaRecId=UuidOpt.getUuidAsString32();
                	String nextUserId=request.getParameter("nextUser");
                	IUserInfo user= CodeRepositoryUtil.getUserInfoByCode(cud.getUserCode());
                	IUnitInfo unitInfo= CodeRepositoryUtil.getUnitInfoByCode(cud.getCurrentUnitCode());
                	IUserInfo nextUser= CodeRepositoryUtil.getUserInfoByCode(nextUserId);
                	IUnitInfo nextUnit= CodeRepositoryUtil.getUnitInfoByCode(nextUser.getPrimaryUnit());
                	//新增日志
                	IdeaInfo ideaInfo=new IdeaInfo(ideaRecId,flowRecId,user,unitInfo,"已办",new Date(),dbAirplaneBaseinfo.getRecId(),"日常维护变更");
                	ideaInfoMag.saveNewObject(ideaInfo);
                	IdeaInfo ideaNext=new IdeaInfo(UuidOpt.getUuidAsString32(),flowRecId,nextUser,nextUnit,"待办理",null,dbAirplaneBaseinfo.getRecId(),"日常维护变更");
                	ideaInfoMag.saveNewObject(ideaNext);
                	
                	
                	//新增节点信息
                	FlowNode node=new FlowNode();
                	node.setFlowRecId(flowRecId);
                	node.setRecId(UuidOpt.getUuidAsString32());
                	node.setIdeaRecId(ideaRecId);
                	node.setStatus("N");
                	node.setNodeName("日常维护变更");
                	node.setNodeNum(1);
                	node.setNextUserCode(nextUserId);
                	node.setNextUserUnit(nextUnit.getUnitCode());
                	node.setStatus("N");
                	flowNodeMag.saveNewObject(node);
            		
            		
            		
            		/*FlowInstance flowInstance =	flowEngineClient.createInstanceLockFirstNode("263", name, airplaneBaseinfo.getRecId(), cud.getUserCode(), cud.getCurrentUnitCode());
            		if(flowInstance!=null){
    				Long flowInstId = flowInstance.getFlowInstId();
    				List<String> userCodeSet =new ArrayList<String>();
    				userCodeSet.add(cud.getUserCode());
    				flowEngineClient.assignFlowWorkTeam(flowInstId, "operator", userCodeSet);//添加经办人
    				//flowEngineClient.saveFlowVariable(flowInstId, "fjxz", bgtype);
    				airplaneBaseinfoMag.insertFlow(flowInstId, "fjxz", dbAirplaneBaseinfo.getNature());
    				flowEngineClient.submitOpt(flowInstance.getFirstNodeInstance().getNodeInstId(), cud.getUserCode(), cud.getCurrentUnitCode(), null, null);
    				NodeInstance nodeInstance = 	flowInstance.getFirstNodeInstance();
    				Long nodeInstId =  nodeInstance.getNodeInstId();
    				String nodeCode = nodeInstance.getNodeCode();
    				//保存流程日志
    				airplaneBaseinfoMag.insertFlowLog(UuidOpt.getUuidAsString32(), flowInstId, nodeInstId, cud.getCurrentUnitCode(), cud.getUserCode(), new Date(), "日常运营变更", nodeCode);
    				dbAirplaneBaseinfo.setFlowInsId(flowInstId+"");
            		}*/
            	}
            	} catch (Exception e) {
    				e.printStackTrace();
    			}
            airplaneBaseinfoMag.mergeObject(dbAirplaneBaseinfo);
            	
        }
        JsonResultUtils.writeSingleDataJson("操作成功",response);
    }
    
    /**
     * @Title: getOrgZtree
     * @Description: 加载计划
     * @param @param request
     * @param @param response    参数
     * @return void    返回类型
     * @throws
     */
     @RequestMapping(value = "/ztree", method = RequestMethod.GET)
	public void getOrgZtree(HttpServletRequest request, HttpServletResponse response) {
    	 JSONArray nodes = new JSONArray();
    	 Map<String, Object> map = new HashMap<>();
    	 map.put("dataValid", "T");
    	 map.put("ghStatus", "1");
    	 map.put(CodeBook.SELF_ORDER_BY," ins_time desc");
    	 CentitUserDetails cud = getLoginUser(request);
        
    	 List<Jdghgl> list = jdghglMag.listObjects( map);
    	 for(Jdghgl jdghgl : list) {
    		 JSONObject node = new JSONObject();
    		 node.put("id", jdghgl.getRecId());
    		 node.put("name", jdghgl.getGhName());
    		 node.put("pId", "");
			 nodes.add(node);
    	 }
    	 JsonResultUtils.writeOriginalJson(nodes.toJSONString(), response);
     }
     
     /**
      * 保存文件信息   saveFile
      *
      * @param airplaneBaseinfo  {@link AirplaneBaseinfo}
      * @return
      */
     @RequestMapping(value = "/saveFile", method = {RequestMethod.POST})
     public void saveFile(HttpServletRequest request, HttpServletResponse response) {
     	 String recId = request.getParameter("recId");
     	 String fileType = request.getParameter("fileType");//1:批文，2：合同
     	 String fileId = request.getParameter("fileId");
     	 if(StringUtils.isNoneBlank(fileType)&&StringUtils.isNoneBlank(recId)&&StringUtils.isNoneBlank(fileId)){
     		AirplaneBaseinfo dbAirplaneBaseinfo  =     			
 					airplaneBaseinfoMag.getObjectById( recId);
     		 switch (fileType){
     		case "1":
     			if(dbAirplaneBaseinfo!=null){
     				dbAirplaneBaseinfo.setPw(fileId);
     				airplaneBaseinfoMag.mergeObject(dbAirplaneBaseinfo);
     			}
     			break;
     		case "2":
     			if(dbAirplaneBaseinfo!=null){
     				dbAirplaneBaseinfo.setHt(fileId);
     				airplaneBaseinfoMag.mergeObject(dbAirplaneBaseinfo);
     			}
     			break;	
     		}
     	 }
         JsonResultUtils.writeSingleDataJson("操作成功",response);
     }
     
     /**
      * 保存合同信息   saveFile
      *
      * @param airplaneBaseinfo  {@link AirplaneBaseinfo}
      * @return
      */
     @RequestMapping(value = "/saveHt/{recId}", method = {RequestMethod.PUT})
     public void saveHt(@PathVariable String recId, 
    	    	@Valid AirplaneBaseinfo airplaneBaseinfo,HttpServletRequest request, HttpServletResponse response) {
     		AirplaneBaseinfo dbAirplaneBaseinfo  =     			
 					airplaneBaseinfoMag.getObjectById( recId);
     	
     				dbAirplaneBaseinfo.setHt(airplaneBaseinfo.getHt());
     				airplaneBaseinfoMag.mergeObject(dbAirplaneBaseinfo);
     	
         JsonResultUtils.writeSingleDataJson("操作成功",response);
     }
     
     /**
      * 保存批文信息   saveFile
      *
      * @param airplaneBaseinfo  {@link AirplaneBaseinfo}
      * @return
      */
     @RequestMapping(value = "/savePw/{recId}", method = {RequestMethod.PUT})
     public void savePw(@PathVariable String recId, 
    	    	@Valid AirplaneBaseinfo airplaneBaseinfo,HttpServletRequest request, HttpServletResponse response) {
     		AirplaneBaseinfo dbAirplaneBaseinfo  =     			
 					airplaneBaseinfoMag.getObjectById( recId);
     	
     				dbAirplaneBaseinfo.setPw(airplaneBaseinfo.getPw());
     				airplaneBaseinfoMag.mergeObject(dbAirplaneBaseinfo);
     	
         JsonResultUtils.writeSingleDataJson("操作成功",response);
     }
     
     /**
      * 查询飞机详情
      *
      * @param field    json中只保存需要的属性名
      * @param request  {@link HttpServletRequest}
      * @param response {@link HttpServletResponse}
      * @return {data:[]}
     * @throws IOException 
     * @throws ServletException 
      */
     @RequestMapping(value = "/oaview",method = RequestMethod.GET)
     public void view( HttpServletRequest request, HttpServletResponse response) {
    	 String recId = request.getParameter("flowOptTag");
    		 AirplaneBaseinfo airplaneBaseinfo =     			
    	     			airplaneBaseinfoMag.getObjectById( recId);
    		 request.setAttribute("object", airplaneBaseinfo);
    		 try {
				request.getRequestDispatcher("/modules/airplanebaseinfo/airplanebaseinfo/airplanebaseinfo-oaview.jsp").forward(request, response);
			} catch (ServletException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
     }
     
     /**
      * 财务填报表单
      *
      * @param field    json中只保存需要的属性名
      * @param request  {@link HttpServletRequest}
      * @param response {@link HttpServletResponse}
      * @return {data:[]}
     * @throws IOException 
     * @throws ServletException 
      */
     @RequestMapping(value = "/oacwview",method = RequestMethod.GET)
     public void oacwview( HttpServletRequest request, HttpServletResponse response) {
    	 String recId = request.getParameter("flowOptTag");
    		 AirplaneBaseinfo airplaneBaseinfo =     			
    	     			airplaneBaseinfoMag.getObjectById( recId);
    		 request.setAttribute("object", airplaneBaseinfo);
    		 try {
				request.getRequestDispatcher("/modules/airplanebaseinfo/airplanebaseinfo/airplanebaseinfo-oacwinfo.jsp").forward(request, response);
			} catch (ServletException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
     }
     
     /**
      * 变更查看
      *
      * @param field    json中只保存需要的属性名
      * @param request  {@link HttpServletRequest}
      * @param response {@link HttpServletResponse}
      * @return {data:[]}
     * @throws IOException 
     * @throws ServletException 
      */
     @RequestMapping(value = "/bgview",method = RequestMethod.GET)
     public void bgview( HttpServletRequest request, HttpServletResponse response) {
    	 String recId = request.getParameter("flowOptTag");
    		 AirplaneBaseinfo airplaneBaseinfo =     			
    	     			airplaneBaseinfoMag.getObjectById( recId);
    		 request.setAttribute("object", airplaneBaseinfo);
    		 try {
				request.getRequestDispatcher("/modules/airplanebaseinfo/airplanebaseinfo/airplanebaseinfo-bgview.jsp").forward(request, response);
			} catch (ServletException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
     }
     
     /**
      * 三证变更
      *
      * @param field    json中只保存需要的属性名
      * @param request  {@link HttpServletRequest}
      * @param response {@link HttpServletResponse}
      * @return {data:[]}
     * @throws IOException 
     * @throws ServletException 
      */
     @RequestMapping(value = "/szinfo",method = RequestMethod.GET)
     public void szinfo( HttpServletRequest request, HttpServletResponse response) {
    	 String recId = request.getParameter("flowOptTag");
    		 AirplaneBaseinfo airplaneBaseinfo =     			
    	     			airplaneBaseinfoMag.getObjectById( recId);
    		 request.setAttribute("object", airplaneBaseinfo);
    		 try {
				request.getRequestDispatcher("/modules/airplanebaseinfo/airplanebaseinfo/airplanebaseinfo-szinfo.jsp").forward(request, response);
			} catch (ServletException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
     }
     
     /**
      * 财务填报保存
      *
      * @param field    json中只保存需要的属性名
      * @param request  {@link HttpServletRequest}
      * @param response {@link HttpServletResponse}
      * @return {data:[]}
     * @throws ParseException 
     * @throws IOException 
     * @throws ServletException 
      */
     @RequestMapping(value = "/oacwsave",method = RequestMethod.PUT)
     public void oacwsave(@Valid AirplaneBaseinfo airplaneBaseinfo, HttpServletRequest request, HttpServletResponse response) throws ParseException, IOException {
    	 String recId = airplaneBaseinfo.getRecId();
    		 AirplaneBaseinfo dbAirplaneBaseinfo =     			
    	     			airplaneBaseinfoMag.getObjectById( recId);
    		dbAirplaneBaseinfo.copyNotNullProperty(airplaneBaseinfo);//赋值页面不为空的值，小心页面空的字符串或者改写copyNotNullProperty方法，根据自己业务需要
         	dbAirplaneBaseinfo.setEditTime(new Date());
         	airplaneBaseinfoMag.mergeObject(dbAirplaneBaseinfo);
    		 JsonResultUtils.writeSingleDataJson("操作成功",response);
     }
     
     /**
      * 三证填报保存
      *
      * @param field    json中只保存需要的属性名
      * @param request  {@link HttpServletRequest}
      * @param response {@link HttpServletResponse}
      * @return {data:[]}
     * @throws ParseException 
     * @throws IOException 
     * @throws ServletException 
      */
     @RequestMapping(value = "/szsave",method = RequestMethod.POST)
     public void szsave( HttpServletRequest request, HttpServletResponse response) throws ParseException {
    	 String recId = request.getParameter("recId");
    	 String type = request.getParameter("type");
    	 String fileId = request.getParameter("fileId");
    	 if(StringUtils.isNoneBlank(recId)&&StringUtils.isNoneBlank(type)){
    		 AirplaneBaseinfo airplaneBaseinfo =     			
 	     			airplaneBaseinfoMag.getObjectById( recId);
    		 if(type.equals("1")){
    			 airplaneBaseinfo.setDtz(fileId);
    		 }else if(type.equals("2")){
    			 airplaneBaseinfo.setShz(fileId);
    		 }else if(type.equals("3")){
    			 airplaneBaseinfo.setGjz(fileId);
    		 }
    		 airplaneBaseinfoMag.mergeObject(airplaneBaseinfo);
    		 JsonResultUtils.writeSingleDataJson("操作成功",response);
    	 }
    		
     }
     
     /**
      * 流程跳转页面
      *
      */
     @RequestMapping(value = "/oa/{type}",method = RequestMethod.GET)
     public void oaview(@PathVariable String type, HttpServletRequest request, HttpServletResponse response) {
    	 String recId = request.getParameter("flowOptTag");
    		 AirplaneBaseinfo airplaneBaseinfo =     			
    	     			airplaneBaseinfoMag.getObjectById( recId);
    		 request.setAttribute("object", airplaneBaseinfo);
    		 request.setAttribute("transContent", request.getParameter("transContent"));
    		 try {
    			 String view = "/modules/airplanebaseinfo/oa/airplanebaseinfo-header.jsp";
    			 switch (type){
    	     		case "header":
    	     			if (StringUtils.isNotEmpty(airplaneBaseinfo.getAirZt())) {
    	    				airplaneBaseinfo.setAirZt(CodeRepositoryUtil.getValue("AIRZT", airplaneBaseinfo.getAirZt()));
    	                }
    	                if (StringUtils.isNotEmpty(airplaneBaseinfo.getNature())) {
    	                	airplaneBaseinfo.setNature(CodeRepositoryUtil.getValue("AIRXZ", airplaneBaseinfo.getNature()));
    	                }
    	                request.setAttribute("object", airplaneBaseinfo);
    	     			view = "/modules/airplanebaseinfo/oa/airplanebaseinfo-header.jsp";
    	     			break;
    	     		case "view":
    	    			if (StringUtils.isNotEmpty(airplaneBaseinfo.getAirZt())) {
    	    				airplaneBaseinfo.setAirZt(CodeRepositoryUtil.getValue("AIRZT", airplaneBaseinfo.getAirZt()));
    	                }
    	                if (StringUtils.isNotEmpty(airplaneBaseinfo.getNature())) {
    	                	airplaneBaseinfo.setNature(CodeRepositoryUtil.getValue("AIRXZ", airplaneBaseinfo.getNature()));
    	                }
    	                request.setAttribute("object", airplaneBaseinfo);
    	     			view = "/modules/airplanebaseinfo/oa/airplanebaseinfo-view.jsp";
    	     			break;
    	     		case "edit":
    	     			view = "/modules/airplanebaseinfo/oa/airplanebaseinfo-edit.jsp";
    	     			break;
    	     		case "ghadd":
    	     			view = "/modules/airplanebaseinfo/oa/airplanebaseinfo-ghadd.jsp";
    	     			break;
    	     		case "cwadd":
    	     			view = "/modules/airplanebaseinfo/oa/airplanebaseinfo-oacwadd.jsp";
    	     			break;
    	     		case "center":
    	     			view = "/modules/airplanebaseinfo/oa/airplanebaseinfo-center.jsp";
    	     			break;
    	     		case "jwadd":
    	     			view = "/modules/airplanebaseinfo/oa/airplanebaseinfo-jwadd.jsp";
    	     			break;
    	     		case "flowedit":
    	     			view = "/modules/airplanebaseinfo/oa/airplanebaseinfo-flowedit.jsp";
    	     			break;
    	     		case "pw":
    	     			view = "/modules/airplanebaseinfo/oa/airplanebaseinfo-pw.jsp";
    	     			break;
    	     		case "floweditpw":
    	     			view = "/modules/airplanebaseinfo/oa/airplanebaseinfo-floweditpw.jsp";
    	     			break;
    	     		case "jwview":
    	     			view = "/modules/airplanebaseinfo/oa/airplanebaseinfo-jwview.jsp";
    	     			break;
    	     		case "cz":
    	     			view = "/modules/airplanebaseinfo/oa/airplanebaseinfo-cz.jsp";
    	     			break;
    			 }
				request.getRequestDispatcher(view).forward(request, response);
			} catch (ServletException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
     }
     
     /**
      * 更新 飞机基础信息 
     
 	 * @param recId  REC_ID
 	 * @param airplaneBaseinfo  {@link AirplaneBaseinfo}
      * @param response    {@link HttpServletResponse}
      */
     @RequestMapping(value = "/saveAir/{recId}", method = {RequestMethod.PUT})
     public void saveAirplaneBaseinfo(@PathVariable String recId, 
     	@Valid AirplaneBaseinfo airplaneBaseinfo, HttpServletResponse response, HttpServletRequest request) {
     	CentitUserDetails cud = getLoginUser(request);
     	
     	AirplaneBaseinfo dbAirplaneBaseinfo  =     			
     			airplaneBaseinfoMag.getObjectById( recId);
         if (null != dbAirplaneBaseinfo) {//如果数据库数据存在，则是更新操作
         	dbAirplaneBaseinfo .copyNotNullProperty(airplaneBaseinfo);//赋值页面不为空的值，小心页面空的字符串或者改写copyNotNullProperty方法，根据自己业务需要
         	dbAirplaneBaseinfo.setEditUsercode(cud.getUserCode());
         	dbAirplaneBaseinfo.setEditTime(new Date());
         	airplaneBaseinfoMag.mergeObject(dbAirplaneBaseinfo);
         }
         JsonResultUtils.writeSingleDataJson("操作成功",response);
     }
     
     /**
      * 机务填报保存
      *
      * @param field    json中只保存需要的属性名
      * @param request  {@link HttpServletRequest}
      * @param response {@link HttpServletResponse}
      * @return {data:[]}
     * @throws ParseException 
     * @throws IOException 
     * @throws ServletException 
      */
     /*@RequestMapping(value = "/oajwsave",method = RequestMethod.POST)
     public void oajwsave( HttpServletRequest request, HttpServletResponse response) throws ParseException {
    	 SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
    	 String recId = request.getParameter("recId");
    	 String ccxlh = request.getParameter("ccxlh");
    	 String zch = request.getParameter("zch");
    	 String fsn = request.getParameter("fsn");
    	 String sign = request.getParameter("sign");
    	 String airModel = request.getParameter("airModel");
    	 String airZzs = request.getParameter("airZzs");
    	 String proctionDate = request.getParameter("proctionDate");
    	 String useDate = request.getParameter("useDate");
    	 String jrygrq = request.getParameter("jrygrq");
    	 String tcygrq = request.getParameter("tcygrq");
    	 String offDate = request.getParameter("offDate");
    	 String apu = request.getParameter("apu");
    	 String engineS = request.getParameter("engineS");
    	 String engine = request.getParameter("engine");
    	 String oneSn = request.getParameter("oneSn");
    	 String twoSn = request.getParameter("twoSn");
    	 String hud = request.getParameter("hud");
    	 String wifi = request.getParameter("wifi");
    	 String maxZl = request.getParameter("maxZl");
    	 String gjNo = request.getParameter("gjNo");
    	 String gjDate = request.getParameter("gjDate");
    	 String bzfj = request.getParameter("bzfj");
    	 String haveName = request.getParameter("haveName");
    	 String haveAddr = request.getParameter("haveAddr");
    	 String yyName = request.getParameter("yyName");
    	 String shNo = request.getParameter("shNo");
    	 String qfDate = request.getParameter("qfDate");
    	 String hjNo = request.getParameter("hjNo");
    	 String addrNoHex = request.getParameter("addrNoHex");
    	 String addrNoOct = request.getParameter("addrNoOct");
    	 String dtNo = request.getParameter("dtNo");
    	 String dtyxDate = request.getParameter("dtyxDate");
    	 String dtbfDate = request.getParameter("dtbfDate");
    	 String zwbj = request.getParameter("zwbj");
    	 String dtz = request.getParameter("dtz");
    	 String shz = request.getParameter("shz");
    	 String gjz = request.getParameter("gjz");
    		 AirplaneBaseinfo airplaneBaseinfo =     			
    	     			airplaneBaseinfoMag.getObjectById( recId);
    		 airplaneBaseinfo.setCcxlh(ccxlh);
    		 airplaneBaseinfo.setZch(zch);
    		 airplaneBaseinfo.setFsn(fsn);
    		 airplaneBaseinfo.setAirModel(airModel);
    		 airplaneBaseinfo.setSign(sign);
    		 airplaneBaseinfo.setAirZzs(airZzs);
    		 if(StringUtils.isNoneBlank(proctionDate)){
    			 airplaneBaseinfo.setProctionDate(sdf2.parse(proctionDate)); 
    		 }
    		 if(StringUtils.isNoneBlank(useDate)){
    			 airplaneBaseinfo.setUseDate(sdf2.parse(useDate));
    		 }
    		 if(StringUtils.isNoneBlank(jrygrq)){
    			 airplaneBaseinfo.setJrygrq(sdf2.parse(jrygrq));
    		 }
    		 if(StringUtils.isNoneBlank(tcygrq)){
    			 airplaneBaseinfo.setTcygrq(sdf2.parse(tcygrq));
    		 }
    		 if(StringUtils.isNoneBlank(offDate)){
    			 airplaneBaseinfo.setOffDate(sdf2.parse(offDate));
    		 }
    		 airplaneBaseinfo.setApu(apu);
    		 airplaneBaseinfo.setEngine(engine);
    		 airplaneBaseinfo.setEngineS(engineS);
    		 airplaneBaseinfo.setOneSn(oneSn);
    		 airplaneBaseinfo.setTwoSn(twoSn);
    		 airplaneBaseinfo.setHud(hud);
    		 airplaneBaseinfo.setWifi(wifi);
    		 airplaneBaseinfo.setMaxZl(maxZl);
    		 airplaneBaseinfo.setGjNo(gjNo);
    		 if(StringUtils.isNoneBlank(gjDate)){
    			 airplaneBaseinfo.setGjDate(sdf2.parse(gjDate));
    		 }
    		 if(StringUtils.isNoneBlank(qfDate)){
    			 airplaneBaseinfo.setQfDate(sdf2.parse(qfDate));
    		 }
    		 if(StringUtils.isNoneBlank(dtyxDate)){
    			 airplaneBaseinfo.setDtyxDate(sdf2.parse(dtyxDate));
    		 }
    		 if(StringUtils.isNoneBlank(dtbfDate)){
    			 airplaneBaseinfo.setDtbfDate(sdf2.parse(dtbfDate));
    		 }
    		 airplaneBaseinfo.setBzfj(bzfj);
    		 airplaneBaseinfo.setHaveName(haveName);
    		 airplaneBaseinfo.setHaveAddr(haveAddr);
    		 airplaneBaseinfo.setYyName(yyName);
    		 airplaneBaseinfo.setShNo(shNo);
    		 airplaneBaseinfo.setHjNo(hjNo);
    		 airplaneBaseinfo.setAddrNoHex(addrNoHex);
    		 airplaneBaseinfo.setAddrNoOct(addrNoOct);
    		 airplaneBaseinfo.setDtNo(dtNo);
    		 airplaneBaseinfo.setZwbj(zwbj);
    		 airplaneBaseinfo.setDtz(dtz);
    		 airplaneBaseinfo.setShz(shz);
    		 airplaneBaseinfo.setGjz(gjz);
    		 airplaneBaseinfoMag.mergeObject(airplaneBaseinfo);
    		 JsonResultUtils.writeSingleDataJson("操作成功",response);
     }*/
     
     /**
      * 导出飞机详情
      *
      * @param request  {@link HttpServletRequest}
      * @param response {@link HttpServletResponse}
      */
     @RequestMapping(value = "/export",method = RequestMethod.GET)
     public void export( HttpServletRequest request, HttpServletResponse response) {
    	 String recId = request.getParameter("flowOptTag");
    	 AirplaneBaseinfo airplaneBaseinfo= airplaneBaseinfoMag.getObjectById( recId);
    	 JSONObject js =(JSONObject) JSONObject.toJSON(airplaneBaseinfo);
     	 JSONArray jsonArrayObjects = new JSONArray();
     	 jsonArrayObjects.add(js);
     	String text = "[{\"name\":\"电台证\",\"value\":\"dtz\"},{\"name\":\"适航证\",\"value\":\"shz\"},{\"name\":\"国籍证\",\"value\":\"gjz\"}"
     			+ ",{\"name\":\"合同\",\"value\":\"ht\"},{\"name\":\"批文\",\"value\":\"pw\"}]";
     	JSONArray jsonArray = JSONArray.parseArray(text);
      	 //下载附件
     	 try {
			ZipUtil.creartDir(jsonArrayObjects, jsonArray,response);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	 
     }
     
     @RequestMapping(value = "/importAir",method = RequestMethod.GET)
     public void importAir( HttpServletRequest request, HttpServletResponse response) {
    	 try {
    		List<AirplaneBaseinfo> list= readXls();
         	for (int i = 0; i < list.size(); i++) {
         		airplaneBaseinfoMag.saveNewObject(list.get(i));
 			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	 
     }
     

	 private  List<AirplaneBaseinfo> readXls() throws IOException, Exception {  
	        InputStream is = new FileInputStream("D:/1.xlsx");  
	        XSSFWorkbook hssfWorkbook = new XSSFWorkbook(is);  
	        AirplaneBaseinfo obj = null;  
	        List<AirplaneBaseinfo> list = new ArrayList<AirplaneBaseinfo>();  
	        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); 
	        SimpleDateFormat sdf2=new SimpleDateFormat("yyyy/MM/dd hh:mm:ss"); 
	        // 循环工作表Sheet  
	        for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++) {  
	            XSSFSheet hssfSheet = hssfWorkbook.getSheetAt(numSheet);  
	            if (hssfSheet == null) {  
	                continue;  
	            }  
	            // 循环行Row  
	            for (int rowNum = 1; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {  
	            	
	            	System.out.println("当前数据行数:"+rowNum); 
	                XSSFRow hssfRow = hssfSheet.getRow(rowNum);  
	                if (hssfRow == null) {  
	                    continue;  
	                }  
	                obj = new AirplaneBaseinfo();  
	                int i=0;
	                obj.setDataValid("T");
	                obj.setRecId(getValue(hssfRow.getCell(i)));  
	                obj.setTitle(getValue(hssfRow.getCell(++i)));  
	               String zt=getValue(hssfRow.getCell(++i));
	                if("计划交付".equals(zt)){
	                	obj.setAirZt("1");
	                	obj.setStatus("1");
	                }else if("实际运营".equals(zt)){
	                	obj.setAirZt("2");
	                	obj.setStatus("2");
	                }else if("退出运营".equals(zt)){
	                	obj.setAirZt("3");
	                	obj.setStatus("3");
	                }else{
	                	obj.setAirZt("4");
	                }
	                String xz=getValue(hssfRow.getCell(++i));
	                if("融租".equals(xz)){
	                	obj.setNature("1");
	                }else if("经租".equals(xz)){
	                	obj.setNature("2");
	                }else if("自有".equals(xz)){
	                	obj.setNature("3");
	                }else{
	                	obj.setNature(null);
	                }
	               
	                int tmp=++i;
	                if("".equals(getValue(hssfRow.getCell(tmp)))){
	                	 obj.setEndTime(null);
	                }else{
	                	 obj.setEndTime(sdf.parse(getValueDate(hssfRow.getCell(tmp))));
	                }
	                
	                obj.setSign(getValue(hssfRow.getCell(++i)));  
	                obj.setAirModel(getValue(hssfRow.getCell(++i)));  
	                obj.setCcxlh(getValue(hssfRow.getCell(++i))); 
	                 tmp=++i;
	                 
	                if("".equals(getValue(hssfRow.getCell(tmp)))){
	                	 obj.setProctionDate(null);
	                }else{
	                	 obj.setProctionDate(sdf.parse(getValueDate(hssfRow.getCell(tmp))));
	                }
	                

	                
	                tmp=++i;
	                 
	                if("".equals(getValue(hssfRow.getCell(tmp)))){
	                	 obj.setUseDate(null);
	                }else{
	                	 obj.setUseDate(sdf.parse(getValueDate(hssfRow.getCell(tmp))));
	                	 obj.setDjsj(sdf.format(obj.getUseDate()));
	                }
	                
	                tmp=++i;
	                 
	                if("".equals(getValue(hssfRow.getCell(tmp)))){
	                	 obj.setOffDate(null);
	                }else{
	                	 obj.setOffDate(sdf.parse(getValueDate(hssfRow.getCell(tmp))));
	                }
	                
	                obj.setEngineS(getValue(hssfRow.getCell(++i)));  
	                obj.setEngine(getValue(hssfRow.getCell(++i)));  
	                obj.setOneSn(getValue(hssfRow.getCell(++i)));  
	                obj.setTwoSn(getValue(hssfRow.getCell(++i)));  
	                obj.setGjNo(getValue(hssfRow.getCell(++i)));  
	                tmp=++i;
	                 
	                if("".equals(getValue(hssfRow.getCell(tmp)))){
	                	 obj.setGjDate(null);
	                }else{
	                	 obj.setGjDate(sdf.parse(getValueDate(hssfRow.getCell(tmp))));
	                }
	                
	                obj.setBzfj(getValue(hssfRow.getCell(++i))); 
	                obj.setHaveName(getValue(hssfRow.getCell(++i)));  
	                obj.setHaveAddr(getValue(hssfRow.getCell(++i)));  
	                obj.setYyName(getValue(hssfRow.getCell(++i)));  
	                obj.setYyAddr(getValue(hssfRow.getCell(++i)));  
	                obj.setShNo(getValue(hssfRow.getCell(++i)));  
	                tmp=++i;
	                 
	                if("".equals(getValue(hssfRow.getCell(tmp)))){
	                	 obj.setQfDate(null);
	                }else{
	                	 obj.setQfDate(sdf.parse(getValueDate(hssfRow.getCell(tmp))));
	                }
	                
	                obj.setHjNo(getValue(hssfRow.getCell(++i))); 
	                obj.setAddrNoHex(getValue(hssfRow.getCell(++i)));  
	                obj.setAddrNoOct(getValue(hssfRow.getCell(++i)));  
	                obj.setDtNo(getValue(hssfRow.getCell(++i)));
	                tmp=++i;
	                 
	                if("".equals(getValue(hssfRow.getCell(tmp)))){
	                	 obj.setDtyxDate(null);
	                }else{
	                	 obj.setDtyxDate(sdf.parse(getValueDate(hssfRow.getCell(tmp))));
	                }
	                
	                tmp=++i;
	                 
	                if("".equals(getValue(hssfRow.getCell(tmp)))){
	                	 obj.setDtbfDate(null);
	                }else{
	                	 obj.setDtbfDate(sdf.parse(getValueDate(hssfRow.getCell(tmp))));
	                }
	                
	                obj.setRemark(getValue(hssfRow.getCell(++i)));  
	                ++i;
	                tmp=++i;
	                 
	                obj.setInsTime(sdf.parse(getValueDate(hssfRow.getCell(tmp))));
	                tmp=++i;
	                 
	                obj.setEditTime(sdf.parse(getValueDate(hssfRow.getCell(tmp))));
	                list.add(obj);  
	            }  
	        }  
	        return list;  
	    }  
	   
	    /**  
	     * 得到Excel表中的值  
	     *  
	     * @param xssfCell  
	     *            Excel中的每一个格子  
	     * @return Excel中每一个格子中的值  
	     */ 
	    @SuppressWarnings("static-access")  
	    private  String getValue(XSSFCell xssfCell) {
	    	if(xssfCell==null){
	    		return null;
	    	}
	    	 if (xssfCell.getCellType() == xssfCell.CELL_TYPE_BOOLEAN) {  
		            // 返回布尔类型的值  
		            return String.valueOf(xssfCell.getBooleanCellValue());  
		        } else if (xssfCell.getCellType() == xssfCell.CELL_TYPE_NUMERIC) {  
		        	DecimalFormat df = new DecimalFormat("0");
		            // 返回数值类型的值  
		            return String.valueOf(df.format(xssfCell.getNumericCellValue()));  
		        }  else {  
		            // 返回字符串类型的值  
		        	return xssfCell.getStringCellValue();  
	        }  
	          
	    }  
	    
	    @SuppressWarnings("static-access")  
	    private  String getValueDate(XSSFCell xssfCell) {
        	try{
        		 return xssfCell.getStringCellValue();  
        	}catch(Exception e){
        		   SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); 
        		 return sdf.format(xssfCell.getDateCellValue());  
        	}
	    }  
}
